package com.mz.ozy.activity.me;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.flyco.tablayout.SlidingTabLayout;
import com.mz.ozy.R;
import com.mz.ozy.adapter.LogisticsFragmentAdapter;
import com.mz.ozy.adapter.LogisticsListAdapter;
import com.mz.ozy.adapter.MyOrderFragmentAdapter;
import com.mz.ozy.adapter.MyOrderListAdapter;
import com.mz.ozy.base.BaseActivity;
import com.mz.ozy.bean.AssetsBean;
import com.mz.ozy.bean.MyOrderBean;
import com.mz.ozy.bean.MyOrderInfoBean1;
import com.mz.ozy.bean.NetBean;
import com.mz.ozy.bean.OrderLogisticsInfoBean;
import com.mz.ozy.mvp.presenter.MyOrderInfoPresenter1;
import com.mz.ozy.mvp.presenter.OrderLogisticsInfoPresenter;
import com.mz.ozy.mvp.view.MyOrderInfoContract1;
import com.mz.ozy.mvp.view.OrderLogisticsInfoContract;
import com.mz.ozy.widget.dialog.BaseDialog;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/11/22.
 * 我的订单
 */

public class OrderLogisticsListActivity extends BaseActivity<MyOrderInfoContract1.View, MyOrderInfoPresenter1> implements MyOrderInfoContract1.View {

    public static int mOrderPosition = 0;

    private String[] titles;
//    @BindView(R.id.tl_tab_layout)
//    SlidingTabLayout mTlTabLayout;
    @BindView(R.id.vp_view_pager)
    ViewPager mVpViewPager;
    private int mType;
    private LogisticsListAdapter mAdapter;
    private String mOrder;
    private int beanType;
    @BindView(R.id.rv_content)
    RecyclerView mRvContent;
    @BindView(R.id.fl_view_empty)
    FrameLayout mFlViewEmpty;

    public static void start(Context context, String order, int type) {
        Intent starter = new Intent(context, OrderLogisticsListActivity.class);
        starter.putExtra("order", order);
        starter.putExtra("type", type);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics_list);
        ButterKnife.bind(this);
        initTitle();
        tvCenterTitle.setText("物流信息");
        mOrder = getIntent().getStringExtra("order");
        // MyOrderFragment
        //  MyOrderFragmentAdapter
        //初始化tabLayout  ViewPage

        //mType = getIntent().getIntExtra("type", MyOrderFragment.TYPE_ALL);
        //titles = getResources().getStringArray(R.array.order_tab);
        //mVpViewPager.setAdapter(new MyOrderFragmentAdapter(getSupportFragmentManager()));
        //mVpViewPager.setAdapter(new LogisticsFragmentAdapter(getSupportFragmentManager()));
//        LogisticsFragment.start(this,mOrder,beanType);
        //LogisticsFragment.newInstance(mOrder,10,0);
        //mTlTabLayout.setViewPager(mVpViewPager, titles);
//        mOrder = getIntent().getStringExtra("order");
//        beanType = getIntent().getIntExtra("beanType", 0);
        mPresenter.initData(this, mOrder, beanType);
        //init();
    }
    private List<MyOrderInfoBean1.OrdermapBean.ProdcutListBean.ListsEntitiesBean> mPageItemsBeans = new ArrayList<>();
    private void init() {
        //this.onEmpty();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String data1 = dateFormat.format(date);

        //mAdapter = new LogisticsListAdapter(mPageItemsBeans, data1);
//        mRvContent.setLayoutManager(new LinearLayoutManager(getContext()));
//        mRvContent.setAdapter(mAdapter);
//        mRvContent.setFocusableInTouchMode(false);
//        mRvContent.setFocusable(false);
//        mRvContent.setHasFixedSize(true);

        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                final MyOrderBean.OrderBean.PageItemsBean bean = (MyOrderBean.OrderBean.PageItemsBean) adapter.getData().get(position);
                if (bean == null) return;
                switch (view.getId()) {
                    case R.id.btn_evaluate://查看物流
//                        MyOrderInfoActivity.start(getContext(), bean.getTesq(), String.valueOf(bean.getId()), bean.getState(), dataItem.getUser_balance(), bean.getType(), 0);
                        break;
                }
            }
        });
    }


    @Override
    public void onInitSuccess(MyOrderInfoBean1 myOrderInfoBean) {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String data1 = dateFormat.format(date);
        final List<MyOrderInfoBean1.OrdermapBean.ProdcutListBean> prodcut_list = myOrderInfoBean.getOrdermap().getProdcut_list();
//        for (MyOrderInfoBean1.OrdermapBean.ProdcutListBean mpBean : prodcut_list) {
//            mPageItemsBeans.add(mpBean);
//        }
        mAdapter = new LogisticsListAdapter(this,prodcut_list,mOrder,"");
        //mRvContent.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvContent.setAdapter(mAdapter);
        mRvContent.setFocusableInTouchMode(false);
        mRvContent.setFocusable(false);
        mRvContent.setHasFixedSize(true);

        mFlViewEmpty.setVisibility(View.GONE);
    }

    @Override
    public void onInitError(String msg) {

    }

    @Override
    public void onConfirmSuccess(NetBean netBean) {

    }

    @Override
    public void onConfirmError(String msg) {

    }

    @Override
    public void onCancelOrderSuccess(NetBean netBean) {

    }

    @Override
    public void onCancelOrderError(String msg) {

    }

    @Override
    public void onDelOrderSuccess(NetBean netBean) {

    }

    @Override
    public void onDelOrderError(String msg) {

    }

    @Override
    public void geAssetsInfoSuccess(AssetsBean bean) {

    }

    @Override
    public void onPaySuccess(JSONObject orderBean) {

    }

    @Override
    public void onPayError(String s) {

    }
}
